<!DOCTYPE html>
<html>

<head>
  <title>Quarkus - Deploying on OpenShift</title>
  <script id="adobe_dtm" src="https://www.redhat.com/dtm.js" type="text/javascript"></script>
  <script src="/assets/javascript/highlight.pack.js" type="text/javascript"></script>
  <META HTTP-EQUIV='Content-Security-Policy' CONTENT="default-src 'none'; script-src 'self' 'unsafe-eval' 'sha256-ANpuoVzuSex6VhqpYgsG25OHWVA1I+F6aGU04LoI+5s=' 'sha256-ipy9P/3rZZW06mTLAR0EnXvxSNcnfSDPLDuh3kzbB1w=' js.bizographics.com https://www.redhat.com assets.adobedtm.com jsonip.com https://ajax.googleapis.com https://www.googletagmanager.com https://www.google-analytics.com https://use.fontawesome.com; style-src 'self' https://fonts.googleapis.com https://use.fontawesome.com; img-src 'self' *; media-src 'self' ; frame-src https://www.googletagmanager.com https://www.youtube.com; frame-ancestors 'none'; base-uri 'none'; object-src 'none'; form-action 'none'; font-src 'self' https://use.fontawesome.com https://fonts.gstatic.com;">
  <META HTTP-EQUIV='X-Frame-Options' CONTENT="DENY">
  <META HTTP-EQUIV='X-XSS-Protection' CONTENT="1; mode=block">
  <META HTTP-EQUIV='X-Content-Type-Options' CONTENT="nosniff">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Quarkus: Supersonic Subatomic Java">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:site" content="@QuarkusIO"> 
  <meta name="twitter:creator" content="@QuarkusIO">
  <meta property="og:url" content="https://quarkus.io/guides/deploying-to-openshift" />
  <meta property="og:title" content="Quarkus - Deploying on OpenShift" />
  <meta property="og:description" content="Quarkus: Supersonic Subatomic Java" />
  <meta property="og:image" content="/assets/images/quarkus_card.png" />
  <link rel="canonical" href="https://quarkus.io/guides/deploying-to-openshift">
  <link rel="shortcut icon" type="image/png" href="/favicon.ico" >
  <link rel="stylesheet" href="https://quarkus.io/guides/stylesheet/config.css" />
  <link rel="stylesheet" href="/assets/css/main.css" />
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  <link rel="alternate" type="application/rss+xml"  href="https://quarkus.io/feed.xml" title="Quarkus">
  <script src="https://quarkus.io/assets/javascript/goan.js" type="text/javascript"></script>
  <script src="https://quarkus.io/assets/javascript/hl.js" type="text/javascript"></script>
</head>

<body class="guides">
  <!-- Google Tag Manager (noscript) -->
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NJWS5L"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <!-- End Google Tag Manager (noscript) -->

  <div class="nav-wrapper">
  <div class="grid-wrapper">
    <div class="width-12-12">
      <input type="checkbox" id="checkbox" />
      <nav id="main-nav" class="main-nav">
  <div class="container">
    <div class="logo-wrapper">
      
        <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_600px_reverse.png" class="project-logo" title="Quarkus"></a>
      
    </div>
    <label class="nav-toggle" for="checkbox">
      <i class="fa fa-bars"></i>
    </label>
    <div id="menu" class="menu">
      <span>
        <a href="/get-started/" class="">Get Started</a>
      </span>
      <span>
        <a href="/guides/" class="active">Guides</a>
      </span>
      <span>
        <a href="/community/" class="">Community</a>
      </span>
      <span>
        <a href="/support/" class="">Support</a>
      </span>
      <span>
        <a href="/blog/" class="">Blog</a>
      </span>
      <span>
        <a href="https://code.quarkus.io" class="button-cta secondary white">Start Coding</a>
      </span>
    </div>
  </div>
      </nav>
    </div>
  </div>
</div>

  <div class="content">
    <div class="guide">
  <div class="width-12-12">
    <h1 class="text-caps">Quarkus - Deploying on OpenShift</h1>
    <div class="hide-mobile toc"><ul class="sectlevel1">
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#creating-the-maven-project">Creating the Maven project</a>
<ul class="sectlevel2">
<li><a href="#openshift">OpenShift</a></li>
<li><a href="#building">Building</a></li>
<li><a href="#non-s2i-builds">Non S2i Builds</a></li>
<li><a href="#deploying">Deploying</a></li>
<li><a href="#customizing">Customizing</a></li>
</ul>
</li>
</ul></div>
    <div>
      <div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>This guide covers generating and deploying OpenShift resources based on sane default and user supplied configuration.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="prerequisites"><a class="anchor" href="#prerequisites"></a>Prerequisites</h2>
<div class="sectionbody">
<div class="paragraph">
<p>To complete this guide, you need:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>roughly 5 minutes</p>
</li>
<li>
<p>an IDE</p>
</li>
<li>
<p>JDK 1.8+ installed with <code>JAVA_HOME</code> configured appropriately</p>
</li>
<li>
<p>Apache Maven 3.6.2+</p>
</li>
<li>
<p>access to an OpenShift cluster (Minishift is a viable option)</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="creating-the-maven-project"><a class="anchor" href="#creating-the-maven-project"></a>Creating the Maven project</h2>
<div class="sectionbody">
<div class="paragraph">
<p>First, we need a new project that contains the OpenShift extension. This can be done using the following command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">mvn io.quarkus:quarkus-maven-plugin:1.7.0.Final:create \
    -DprojectGroupId=org.acme \
    -DprojectArtifactId=openshift-quickstart \
    -DclassName="org.acme.rest.GreetingResource" \
    -Dpath="/greeting" \
    -Dextensions="openshift"

cd openshift-quickstart</code></pre>
</div>
</div>
<div class="sect2">
<h3 id="openshift"><a class="anchor" href="#openshift"></a>OpenShift</h3>
<div class="paragraph">
<p>Quarkus offers the ability to automatically generate OpenShift resources based on sane default and user supplied configuration.
The OpenShift extension is actually a wrapper extension that brings together the <a href="deploying-to-kubernetes">kubernetes</a> and <a href="container-image#s2i">container-image-s2i</a>
extensions with sensible defaults so that it&#8217;s easier for the user to get started with Quarkus on OpenShift.</p>
</div>
<div class="paragraph">
<p>When we added the OpenShift extension to the command line invocation above, the following dependency was added to the <code>pom.xml</code></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs">    &lt;dependency&gt;
      &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
      &lt;artifactId&gt;quarkus-openshift&lt;/artifactId&gt;
    &lt;/dependency&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>By adding this dependency, we now have the ability to configure the OpenShift resource generation and application using the usual <code>application.properties</code> approach that Quarkus provides.
The configuration items that are available can be found in: <code>io.quarkus.kubernetes.deployment.OpenShiftConfig</code> class.
Furthermore, the items provided by <code>io.quarkus.deployment.ApplicationConfig</code> affect the OpenShift resources.</p>
</div>
</div>
<div class="sect2">
<h3 id="building"><a class="anchor" href="#building"></a>Building</h3>
<div class="paragraph">
<p>Building is handled by the <a href="container-image#s2i">container-image-s2i</a> extension. To trigger a build:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">./mvnw clean package -Dquarkus.container-image.build=true</code></pre>
</div>
</div>
<div class="paragraph">
<p>The build that will be performed is an s2i binary build. The input of the build is the jar that has been built locally and the output of the build is an ImageStream that is configured to automatically trigger a deployment.</p>
</div>
</div>
<div class="sect2">
<h3 id="non-s2i-builds"><a class="anchor" href="#non-s2i-builds"></a>Non S2i Builds</h3>
<div class="paragraph">
<p>Out of the box the openshift extension is configured to use <a href="container-image#s2i">container-image-s2i</a>. However, it&#8217;s still possible to use other container image extensions like:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="container-image#s2i">container-image-docker</a></p>
</li>
<li>
<p><a href="container-image#s2i">container-image-jib</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>When a non-s2i container image extension is used, an ImageStream is created that is pointing to an external <code>dockerImageRepository</code>. The image is built and pushed to the registry and the ImageStream populates the tags that are available in the <code>dockerImageRepository</code>.</p>
</div>
<div class="paragraph">
<p>To select which extension will be used for building the image:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">---
quarkus.container-image.builder=docker
---</code></pre>
</div>
</div>
<div class="paragraph">
<p>or</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">---
quarkus.container-image.builder=jib
---</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="deploying"><a class="anchor" href="#deploying"></a>Deploying</h3>
<div class="paragraph">
<p>To trigger a deployment:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">./mvnw clean package -Dquarkus.kubernetes.deploy=true</code></pre>
</div>
</div>
<div class="paragraph">
<p>The command above will trigger a container image build and will apply the generated OpenShift resources, right after.
The generated resources are using OpenShift&#8217;s <code>DeploymentConfig</code> that is configured to automatically trigger a redeployment when a change in the <code>ImageStream</code> is noticed.
In other words, any container image build after the initial deployment will automatically trigger redeployment, without the need to delete, update or re-apply the generated resources.</p>
</div>
</div>
<div class="sect2">
<h3 id="customizing"><a class="anchor" href="#customizing"></a>Customizing</h3>
<div class="paragraph">
<p>All available customization options are available in the <a href="deploying-to-kubernetes#openshift">OpenShift configuration options</a>.</p>
</div>
<div class="paragraph">
<p>Some examples are provided in the sections below:</p>
</div>
<div class="sect3">
<h4 id="exposing-routes"><a class="anchor" href="#exposing-routes"></a>Exposing Routes</h4>
<div class="paragraph">
<p>To expose a <code>Route</code> for the Quarkus application:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">quarkus.openshift.expose=true</code></pre>
</div>
</div>
<div class="paragraph">
<p>Tip: You don&#8217;t necessarily need to add this property in the <code>application.properties</code>. You can pass it as a command line argument:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">./mvnw clean package -Dquarkus.openshift.expose=true</code></pre>
</div>
</div>
<div class="paragraph">
<p>The same applies to all properties listed below.</p>
</div>
</div>
<div class="sect3">
<h4 id="labels"><a class="anchor" href="#labels"></a>Labels</h4>
<div class="paragraph">
<p>To add a label in the generated resources:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">quarkus.openshift.labels.foo=bar</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="annotations"><a class="anchor" href="#annotations"></a>Annotations</h4>
<div class="paragraph">
<p>To add an annotation in the generated resources:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">quarkus.openshift.annotations.foo=bar</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="environment-variables"><a class="anchor" href="#environment-variables"></a>Environment variables</h4>
<div class="paragraph">
<p>To add an annotation in the generated resources:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">quarkus.openshift.env-vars.my-env-var.value=foobar</code></pre>
</div>
</div>
<div class="paragraph">
<p>The command above will add <code>MY_ENV_VAR=foobar</code> as an environment variable.
Please note that the key <code>my-env-var</code> will be converted to uppercase and dashes will be replaced by underscores resulting in <code>MY_ENV_VAR</code>.</p>
</div>
<div class="paragraph">
<p>You may also noticed that in contrast to labels, and annotations for environment variables you don&#8217;t just use a key=value approach.
That is because for environment variables there are additional options rather than just value.</p>
</div>
<div class="sect4">
<h5 id="environment-variables-from-secret"><a class="anchor" href="#environment-variables-from-secret"></a>Environment variables from Secret</h5>
<div class="paragraph">
<p>To add all key value pairs of a <code>Secret</code> as environment variables:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">quarkus.openshift.env-vars.my-env-var.secret=my-secret</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="environment-variables-from-configmap"><a class="anchor" href="#environment-variables-from-configmap"></a>Environment variables from ConfigMap</h5>
<div class="paragraph">
<p>To add all key value pairs of a <code>ConfigMap</code> as environment variables:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">quarkus.openshift.env-vars.my-env-var.configmap=my-secret</code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="mounting-volumes"><a class="anchor" href="#mounting-volumes"></a>Mounting volumes</h4>
<div class="paragraph">
<p>The OpenShift extension allows the user to configure both volumes and mounts for the application.</p>
</div>
<div class="paragraph">
<p>Any volume can be mounted with a simple configuration:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">quarkus.openshift.mounts.my-volume.path=/where/to/mount</code></pre>
</div>
</div>
<div class="paragraph">
<p>This will add a mount to my pod for volume <code>my-volume</code> to path <code>/where/to/mount</code></p>
</div>
<div class="paragraph">
<p>The volumes themselves can be configured as shown in the sections below:</p>
</div>
<div class="sect4">
<h5 id="secret-volumes"><a class="anchor" href="#secret-volumes"></a>Secret volumes</h5>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">quarkus.openshift.secret-volumes.my-volume.secret-name=my-secret</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="configmap-volumes"><a class="anchor" href="#configmap-volumes"></a>ConfigMap volumes</h5>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">quarkus.openshift.config-map-volumes.my-volume.config-map-name=my-secret</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
    </div>
  </div>
</div>

  </div>

  <div class="content project-footer">
  <div class="footer-section">
    <div class="logo-wrapper">
      <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_reverse.svg" class="project-logo" title="Quarkus"></a>
    </div>
  </div>
  <div class="grid-wrapper">
    <p class="grid__item width-3-12">Quarkus is open. All dependencies of this project are available under the <a href='https://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache Software License 2.0</a> or compatible license.<br /><br />This website was built with <a href='https://jekyllrb.com/' target='_blank'>Jekyll</a>, is hosted on <a href='https://pages.github.com/' target='_blank'>Github Pages</a> and is completely open source. If you want to make it better, <a href='https://github.com/quarkusio/quarkusio.github.io' target='_blank'>fork the website</a> and show us what you’ve got.</p>

    
      <div class="width-1-12 project-links">
        <span>Navigation</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="/">Home</a></li>
          
            <li><a href="/guides">Guides</a></li>
          
            <li><a href="/community/#contributing">Contribute</a></li>
          
            <li><a href="/faq">FAQ</a></li>
          
            <li><a href="/get-started">Get Started</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Contribute</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://twitter.com/quarkusio">Follow us</a></li>
          
            <li><a href="https://github.com/quarkusio">GitHub</a></li>
          
            <li><a href="/security">Security&nbsp;policy</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Get Help</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://groups.google.com/forum/#!forum/quarkus-dev">Forums</a></li>
          
            <li><a href="https://quarkusio.zulipchat.com">Chatroom</a></li>
          
        </ul>
      </div>
    

    
      <div class="width-3-12 more-links">
        <span>Quarkus is made of community projects</span>
        <ul class="footer-links">
          
            <li><a href="https://vertx.io/" target="_blank">Eclipse Vert.x</a></li>
          
            <li><a href="https://microprofile.io" target="_blank">Eclipse MicroProfile</a></li>
          
            <li><a href="https://hibernate.org" target="_blank">Hibernate</a></li>
          
            <li><a href="https://netty.io" target="_blank">Netty</a></li>
          
            <li><a href="https://resteasy.github.io" target="_blank">RESTEasy</a></li>
          
            <li><a href="https://camel.apache.org" target="_blank">Apache Camel</a></li>
          
            <li><a href="https://code.quarkus.io/" target="_blank">And many more...</a></li>
          
        </ul>
      </div>
    
  </div>
</div>
  <div class="content redhat-footer">
  <div class="grid-wrapper">
    <span class="licence">
      <i class="fab fa-creative-commons"></i><i class="fab fa-creative-commons-by"></i> <a href="https://creativecommons.org/licenses/by/3.0/" target="_blank">CC by 3.0</a> | <a href="https://www.redhat.com/en/about/privacy-policy">Privacy Policy</a>
    </span>
    <span class="redhat">
      Sponsored by
    </span>
    <span class="redhat-logo">
      <a href="https://www.redhat.com/" target="_blank"><img src="/assets/images/redhat_reversed.svg"></a>
    </span>
  </div>
</div>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" integrity="sha384-8gBf6Y4YYq7Jx97PIqmTwLPin4hxIzQw5aDmUg/DDhul9fFpbbLcLh3nTIIDJKhx" crossorigin="anonymous"></script>
  <script type="text/javascript" src="/assets/javascript/mobile-nav.js"></script>
  <script type="text/javascript" src="/assets/javascript/scroll-down.js"></script>
  <script src="/assets/javascript/satellite.js" type="text/javascript"></script>
  <script src="https://quarkus.io/guides/javascript/config.js" type="text/javascript"></script>
  <script src="/assets/javascript/search-filter.js" type="text/javascript"></script>
  <script src="/assets/javascript/back-to-top.js" type="text/javascript"></script>
</body>

</html>
